home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / core / PhpdocObject.php < prev    next >
Encoding:
PHP Script  |  2001-02-18  |  6.4 KB  |  189 lines

  1. <?php
  2. /**
  3. * Common base class of all phpdoc classes
  4. *
  5. * As a kind of common base class PhpdocObject holds 
  6. * configuration values (e.g. error handling) and debugging
  7. * methods (e.g. introspection()). It does not have a constructor,
  8. * so you can always inheritig Phpdoc classes from this 
  9. * class without any trouble.
  10. *  
  11. * @author   Ulf Wendel <ulf.wendel@phpdoc.de>
  12. * @version  $Id: PhpdocObject.php,v 1.3 2001/02/18 15:29:29 uw Exp $
  13. * @package  PHPDoc
  14. */
  15. class PhpdocObject {
  16.  
  17.     /** 
  18.     * Variable containing the latest exceptions.
  19.     *
  20.     * The way PHPDoc handles errors is a little different from the
  21.     * official PEAR way. PHPDoc methods do not return 
  22.     * error objects but save them to the class variable $err and try
  23.     * to return a value that indicates that an error occured.
  24.     *
  25.     * @var      array
  26.     * @access   public
  27.     */
  28.     var $err = array();
  29.  
  30.     /**
  31.     * Default applicationname for the generated HTML files.
  32.     * 
  33.     * @var  string    
  34.     */
  35.     var $application = "PHPDoc";
  36.     
  37.     /**
  38.     * Use to save warnings.
  39.     * 
  40.     * @var  array
  41.     */
  42.     var $warn;
  43.     
  44.     /**
  45.     * Flag determining wheter to print some status messages or not (default: false)
  46.     *
  47.     * @var  boolean $flag_output
  48.     * @see  setFlagOutput()
  49.     * @since  0.3
  50.     */
  51.     var $flag_output = false;
  52.  
  53.     /**
  54.     * Sets the output flag - if set to true out() and outl() print messages
  55.     *
  56.     * @param    boolean $flagOutput
  57.     * @access   public
  58.     * @see      $flag_output, out(), outl()
  59.     * @since    0.3    
  60.     */
  61.     function setFlagOutput($flagOutput) {
  62.         $this->flag_output = ($flagOutput) ? true : false;
  63.     } // end func setFlagOutput
  64.     
  65.     /**
  66.     * Print a string and flush the output buffer
  67.     *
  68.     * @param    string     $message
  69.     */
  70.     function out($message) {
  71.         if (false == $this->flag_output)
  72.             return;
  73.             
  74.         print $message;
  75.         flush();
  76.     } // end func out
  77.     
  78.     /**
  79.     * Encodes an element name so that it can be used as a file name.
  80.     *
  81.     * @param    string  element name
  82.     * @return   string  url name
  83.     */
  84.     function nameToUrl($name) {
  85.         return preg_replace("@[\s\./\\:]@", "_", $name);
  86.     } // end func nameToUrl
  87.  
  88.     
  89.     /**
  90.     * Print a string, the specified HTML line break sign and flushes the output buffer
  91.     *
  92.     * @param    string  $message
  93.     */
  94.     function outl($message) {
  95.         if (false == $this->flag_output) 
  96.             return;
  97.             
  98.         print "$message\n";
  99.         flush();
  100.     } // end func outl
  101.     
  102.     /**
  103.     * Dumps objects and arrays.
  104.     * 
  105.     * Use this function to get an idea of the internal datastructures used. 
  106.     * The function dumps arrays and objects. It renders the content in 
  107.     * an HTML table. Play with it, you'll see it's very helpful
  108.     * for debugging.
  109.     * 
  110.     * @param    string  $title          Optional title used in the HTML Table
  111.     * @param    mixed   $data           Optional array or object that you want to dump. 
  112.     *                                   Fallback to $this.
  113.     * @param    boolean $userfunction   Optional flag. If set to false userfunction
  114.     *                                   in an object are not shown (default). If set to 
  115.     *                                   true, userfunctions are rendered
  116.     * @access   public
  117.     * @version  0.2
  118.     */
  119.     function introspection($title = "", $data = "", $userfunction = true) {
  120.         
  121.         if ("" == $data)
  122.             $data = $this;
  123.         
  124.         printf('<table border="1" cellspacing="4" cellpadding="4" bordercolor="Silver">%s',
  125.                             $this->CR_HTML
  126.                         );    
  127.                         
  128.         if ("" != $title)
  129.             printf('<tr>%s<td colspan=4><b>%s</b></td>%s</tr>%s', 
  130.                                 $this->CR_HTML,
  131.                                 $title,
  132.                                 $this->CR_HTML,
  133.                                 $this->CR_HTML
  134.                             );
  135.         
  136.         reset($data);
  137.         while (list($k, $v) = each($data)) {
  138.         
  139.             if ("user function" == gettype($v) && !$userfunction) 
  140.                 continue;
  141.             
  142.             if (is_array($v) || is_object($v)) {
  143.                 
  144.                 
  145.                 $color="navy";
  146.                     
  147.                 printf('<tr>
  148.                                     <td align="left" valign="top">
  149.                                         <font color="%s"><pre><b>%s</b></pre></font>
  150.                                     </td>
  151.                                     <td align="left" valign="top"><font color="%s"><pre>=></pre></font></td>
  152.                                     <td align="left" valign="top" colspan=2>',
  153.                                         $color,
  154.                                         $k,
  155.                                         $color,
  156.                                         str_replace("<", "<", $v)
  157.                                 );
  158.                                 
  159.                 $this->introspection("", $v, $userfunction);
  160.                     
  161.                 printf('</td>%s</tr>%s', $this->CR_HTML, $this->CR_HTML);
  162.                 
  163.             }    else {
  164.                 
  165.                 $color="black";
  166.                     
  167.                 printf('<tr>
  168.                                     <td align="left" valign="top">
  169.                                         <font color="%s"><pre><b>%s</b></pre></font>
  170.                                     </td>
  171.                                     <td align="left" valign="top"><pre><font color="%s">=></pre></font></td>
  172.                                     <td align="left" valign="top"><pre><font color="%s">[%s]</font></pre></td>
  173.                                     <td align="left" valign="top"><pre><font color="%s">"%s"</font></pre></td>
  174.                                 </tr>',
  175.                                     $color,
  176.                                     $k,
  177.                                     $color,
  178.                                     $color,
  179.                                     gettype($v),
  180.                                     $color,
  181.                                     str_replace("<", "<", $v)
  182.                                 );
  183.             }
  184.         }
  185.         print '</table>' . $this->CR_HTML;
  186.     } // end func introspection
  187.     
  188. } // end class PhpdocObject
  189. ?>